<template>
  <a-card :bordered="false" class="card-area">
    <div :class="advanced ? 'search' : null">
      <!-- 搜索区域 -->
      <a-form layout="horizontal">
        <div :class="advanced ? null: 'fold'">
          <a-row>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="法人行"
                :labelCol="{span: 5}"
                :wrapperCol="{span: 18, offset: 1}">
                <a-select
                          mode="default"
                          :allowClear="true"
                          style="width: 100%"
                          @change="handleInstChange"
                          v-model="queryParams.instId">
                  <a-select-option v-for="r in instIdData" :key="r.label">{{r.label}}-{{r.value}}</a-select-option>
                </a-select>
<!--                <a-input v-if="!this.user.admin" v-model="queryParams.instId" :value="this.user.instId"
                         readonly="readonly"/>-->
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24" v-show="queryParams.instId!=''">
              <a-form-item
                label="银行账/卡号"
                :labelCol="{span: 5}"
                :wrapperCol="{span: 18, offset: 1}">
                <a-input v-model="queryParams.acctNo"/>
              </a-form-item>
            </a-col>
          </a-row>
        </div>
        <div style="text-align: center;margin-bottom: 20px " v-show="queryParams.instId!=''">
          <a-button type="primary" @click="search">查询</a-button>
          <a-button style="margin-left: 8px" @click="reset">重置</a-button>
        </div>
      </a-form>
    </div>
    <div v-show="queryParams.instId!=''">
      <div class="operator">
        <a-button v-hasPermission="['cardBlackList:add']" ghost type="primary" @click="add">新增</a-button>
      </div>
      <!-- 表格区域 -->
      <a-table ref="TableInfo"
               :columns="columns"
               :rowKey="record => record.id"
               :dataSource="dataSource"
               :pagination="pagination"
               :loading="loading"
               :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
               :scroll="{ x: 2600 }"
               @change="handleTableChange">
        <template slot="email" slot-scope="text, record">
          <a-popover placement="topLeft">
            <template slot="content">
              <div>{{text}}</div>
            </template>
            <p style="width: 150px;margin-bottom: 0">{{text}}</p>
          </a-popover>
        </template>
        <template slot="cardBlackListOperation" slot-scope="text, record">
          <a-icon v-hasPermission="['cardBlackList:edit']" type="setting" theme="twoTone" twoToneColor="#4a9ff5"
                  @click="editCardBlackList(record)" title="修改"></a-icon>&nbsp;
          <a-icon v-hasPermission="['cardBlackList:view']" type="eye" theme="twoTone" twoToneColor="#42b983"
                  @click="viewCardBlackList(record)" title="查看"></a-icon>
          <a-badge v-hasNoPermission="['cardBlackList:edit','cardBlackList:view']" userStatus="warning" text="无权限"></a-badge>
        </template>

      </a-table>
      <!-- 品牌信息查看 -->
      <card-black-list-info
        ref="cardBlackListInfo"
        @close="handleCardBlackListInfoClose"
        :cardBlackListInfoVisiable="cardBlackListInfo.visiable">
      </card-black-list-info>
      <!-- 新增品牌 -->
      <card-black-list-add
        @close="handleCardBlackListAddClose"
        @success="handleCardBlackListAddSuccess"
        :cardBlackListAddVisiable="cardBlackListAdd.visiable"
        :instId="this.queryParams.instId">
      </card-black-list-add>

      <!-- 修改品牌 -->
      <card-black-list-edit
        ref="cardBlackListEdit"
        @close="handleCardBlackListEditClose"
        @success="handleCardBlackListEditSuccess"
        :cardBlackListEditVisiable="cardBlackListEdit.visiable"
        :instId="this.queryParams.instId">
      </card-black-list-edit>
    </div>
  </a-card>
</template>

<script>
  import RangeDate from '@/components/datetime/RangeDate'
  import CardBlackListAdd from './CardBlackListAdd'
  import CardBlackListInfo from './CardBlackListInfo'
  import CardBlackListEdit from './CardBlackListEdit'
  import {mapState} from "vuex"

  export default {
    name: "CardBlackList",
    components: {CardBlackListInfo, RangeDate, CardBlackListAdd, CardBlackListEdit},
    data() {
      return {
        advanced: false,
        cardBlackListInfo: {
          visiable: false,
          data: {}
        },
        cardBlackListAdd: {
          visiable: false
        },
        cardBlackListEdit: {
          visiable: false
        },

        queryParams: {
          acctNo: '',
          instId: ''
        },
        dataSource: [],
        sortedInfo: null,
        paginationInfo: null,
        selectedRowKeys: [],
        pagination: {
          pageSizeOptions: ['10', '20', '30', '40', '100'],
          defaultCurrent: 1,
          defaultPageSize: 10,
          showQuickJumper: true,
          showSizeChanger: true,
          showTotal: (total, range) => `显示 ${range[0]} ~ ${range[1]} 条记录，共 ${total} 条记录`
        },
        loading: false,
        instIdData: [],
        da: []
      }
    },
    computed: {
      ...mapState({
        user: state => state.account.user,

      }),
      columns() {
        let {sortedInfo} = this
        sortedInfo = sortedInfo || {}
        let {filteredInfo} = this
        filteredInfo = filteredInfo || {}
        return [{
          title: '法人机构标识',
          dataIndex: 'instId',
          scopedSlots: {customRender: 'instId'},
        }, {
          title: '风险类型',
          dataIndex: 'riskType',
          customRender: (text, row, index) => {
            switch (text) {
              case '11':
                return <a-tag color = "cyan" > 盗用虚拟账户（嫌疑人信息） < /a-tag>
              case '99':
                return <a-tag color = "pink" > 其他 < /a-tag>
              case '01':
                return <a-tag color = "pink" > 虚假申请（受害人信息） < /a-tag>
              case '12':
                return <a-tag color = "pink" > 套现、积分（嫌疑人信息） < /a-tag>
              case '02':
                return <a-tag color = "cyan" > 虚假申请（嫌疑人信息） < /a-tag>
              case '13':
                return <a-tag color = "pink" > 协助转移赃款 < /a-tag>
              case '03':
                return <a-tag color = "pink" > 伪卡（受害人信息） < /a-tag>
              case '14':
                return <a-tag color = "pink" > 买卖或租借银行（支付）账户 < /a-tag>
              case '04':
                return <a-tag color = "cyan" > 失窃卡（受害人信息） < /a-tag>
              case '15':
                return <a-tag color = "pink" > 专案风险信息 < /a-tag>
              case '05':
                return <a-tag color = "pink" > 未达卡（受害人信息） < /a-tag>
              case '06':
                return <a-tag color = "pink" > 银行卡转移（受害人信息） < /a-tag>
              case '17':
                return <a-tag color = "cyan" > 买卖银行卡信息 < /a-tag>
              case '07':
                return <a-tag color = "pink" > 盗用银行卡（嫌疑人信息） < /a-tag>
              case '08':
                return <a-tag color = "pink" > 银行卡网络欺诈（受害人信息） < /a-tag>
              case '09':
                return <a-tag color = "pink" > 银行卡网络欺诈（嫌疑人信息） < /a-tag>
              case '10':
                return <a-tag color = "cyan" > 虚拟账户被盗（受害人信息） < /a-tag>
              default:
                return text
            }
          },
          filters: [
            {text: '盗用虚拟账户（嫌疑人信息）', value: '11'},
            {text: '其他', value: '99'},
            {text: '虚假申请（受害人信息）', value: '01'},
            {text: '套现、积分（嫌疑人信息）', value: '12'},
            {text: '虚假申请（嫌疑人信息）', value: '02'},
            {text: '协助转移赃款', value: '13'},
            {text: '伪卡（受害人信息）', value: '03'},
            {text: '买卖或租借银行（支付）账户', value: '14'},
            {text: '失窃卡（受害人信息）', value: '04'},
            {text: '专案风险信息', value: '15'},
            {text: '未达卡（受害人信息）', value: '05'},
            {text: '银行卡转移（受害人信息）', value: '06'},
            {text: '买卖银行卡信息', value: '17'},
            {text: '盗用银行卡（嫌疑人信息）', value: '07'},
            {text: '银行卡网络欺诈（受害人信息）', value: '08'},
            {text: '银行卡网络欺诈（嫌疑人信息）', value: '09'},
            {text: '虚拟账户被盗（受害人信息）', value: '10'}
          ],
          filterMultiple: false,
          filteredValue: filteredInfo.riskType || null,
          onFilter: (value, record) => record.riskType.includes(value)
        }, {
          title: '银行帐/卡号',
          dataIndex: 'acctNo',
          scopedSlots: {customRender: 'acctNo'},

        }, {
          title: '开户行',
          dataIndex: 'acctOpenBankNo',
          scopedSlots: {customRender: 'acctOpenBankNo'},

        }, {
          title: '客户姓名',
          dataIndex: 'customerName',
          scopedSlots: {customRender: 'customerName'},

        }, {
          title: '身份证件号码',
          dataIndex: 'idCardNo',
          scopedSlots: {customRender: 'idCardNo'},

        }, {
          title: '风险事件发生时间',
          dataIndex: 'riskOccurTimeBegin',
          scopedSlots: {customRender: 'riskOccurTimeBegin'},

        }, {
          title: '风险事件结束时间',
          dataIndex: 'riskOccurTimeEnd',
          scopedSlots: {customRender: 'riskOccurTimeEnd'},

        }, {
          title: '风险事件发生渠道',
          dataIndex: 'riskOccurChannel',
          customRender: (text, row, index) => {
            switch (text) {
              case '01':
                return <a-tag color = "pink" > 线上 < /a-tag>
              case '02':
                return <a-tag color = "pink" > 线下 < /a-tag>
              case '03':
                return <a-tag color = "pink" > 线上兼线下 < /a-tag>
              default:
                return text
            }
          },
          filters: [
            {text: '线上', value: '01'},
            {text: '线下', value: '02'},
            {text: '线上兼线下', value: '03'}
          ],
          filterMultiple: false,
          filteredValue: filteredInfo.riskOccurChannel || null,
          onFilter: (value, record) => record.riskOccurChannel.includes(value)
        }, {
          title: '风险事件发生地域',
          dataIndex: 'riskOccurArea',
          scopedSlots: {customRender: 'riskOccurArea'},

        }, {
          title: '有效性',
          dataIndex: 'validStatus',
          customRender: (text, row, index) => {
            switch (text) {
              case '01':
                return <a-tag color = "pink" > 有效 < /a-tag>
              case '02':
                return <a-tag color = "pink" > 失效 < /a-tag>
              default:
                return text
            }
          },
          filters: [
            {text: '有效', value: '01'},
            {text: '失效', value: '02'},
          ],
          filterMultiple: false,
          filteredValue: filteredInfo.validStatus || null,
          onFilter: (value, record) => record.validStatus.includes(value)
        }, {
          title: '状态',
          dataIndex: 'cardBlacklistStatus',
          customRender: (text, row, index) => {
            switch (text) {
              case '00':
                return <a-tag color = "pink" > 非正式 < /a-tag>
              case '01':
                return <a-tag color = "cyan" > 正式 < /a-tag>
              case '02':
                return <a-tag color = "pink" > 停用 < /a-tag>
              case '03':
                return <a-tag color = "pink" > 已注销 < /a-tag>
              default:
                return text
            }
          },
          filters: [
            {text: '非正式', value: '00'},
            {text: '正式', value: '01'},
            {text: '停用', value: '02'},
            {text: '已注销', value: '03'}
          ],
          filterMultiple: false,
          filteredValue: filteredInfo.cardBlacklistStatus || null,
          onFilter: (value, record) => record.cardBlacklistStatus.includes(value)
        }, {
          title: '审核状态',
          dataIndex: 'auditStatus',
          customRender: (text, row, index) => {
            switch (text) {
              case '00':
                return <a-tag color = "cyan" > 待提交审批 < /a-tag>
              case '01':
                return <a-tag color = "pink" > 新增-审批流程中 < /a-tag>
              case '02':
                return <a-tag color = "pink" > 新增-审批通过 < /a-tag>
              case '03':
                return <a-tag color = "pink" > 新增-审批拒绝 < /a-tag>
              case '11':
                return <a-tag color = "cyan" > 注销-审批流程中 < /a-tag>
              case '12':
                return <a-tag color = "pink" > 注销-审批通过 < /a-tag>
              case '13':
                return <a-tag color = "pink" > 注销-审批拒绝 < /a-tag>
              case '21':
                return <a-tag color = "pink" > 停用-审批流程中 < /a-tag>
              case '22':
                return <a-tag color = "cyan" > 停用-审批通过 < /a-tag>
              case '23':
                return <a-tag color = "pink" > 停用-审批拒绝 < /a-tag>
              case '31':
                return <a-tag color = "pink" > 启用-审批流程中 < /a-tag>
              case '32':
                return <a-tag color = "pink" > 启用-审批通过 < /a-tag>
              case '33':
                return <a-tag color = "cyan" > 启用-审批拒绝 < /a-tag>
              case '41':
                return <a-tag color = "pink" > 修改-审批流程中 < /a-tag>
              case '42':
                return <a-tag color = "pink" > 修改-审批通过 < /a-tag>
              case '43':
                return <a-tag color = "pink" > 修改-审批拒绝 < /a-tag>
              default:
                return text
            }
          },
          filters: [
            {text: '待提交审批', value: '00'},
            {text: '新增-审批流程中', value: '01'},
            {text: '新增-审批通过', value: '02'},
            {text: '新增-审批拒绝', value: '03'},
            {text: '注销-审批流程中', value: '11'},
            {text: '注销-审批通过', value: '12'},
            {text: '注销-审批拒绝', value: '13'},
            {text: '停用-审批流程中', value: '21'},
            {text: '停用-审批通过', value: '22'},
            {text: '停用-审批拒绝', value: '23'},
            {text: '启用-审批流程中', value: '31'},
            {text: '启用-审批通过', value: '32'},
            {text: '启用-审批拒绝', value: '33'},
            {text: '修改-审批流程中', value: '41'},
            {text: '修改-审批通过', value: '42'},
            {text: '修改-审批拒绝', value: '43'}
          ],
          filterMultiple: false,
          filteredValue: filteredInfo.auditStatus || null,
          onFilter: (value, record) => record.auditStatus.includes(value)

        }, {
          title: '操作',
          dataIndex: 'cardBlackListOperation',
          fixed: 'right',
          scopedSlots: {customRender: 'cardBlackListOperation'}
        }]
      }
    },
    mounted() {
      this.$get('admin/upmporg/getInstList').then((r) => {
        this.instIdData = r.data
      })
    },
    methods: {
      onSelectChange(selectedRowKeys) {
        this.selectedRowKeys = selectedRowKeys
      },
      add() {
        this.cardBlackListAdd.visiable = true
      },

      handleInstChange(value) {
        this.queryParams.instId = value;
        if (value != "") {
          let params = {}
          params.instId = value;
          this.$get('/admin/merParam/cardBlackListInfo', {...params}).then((r) => {

            this.dataSource = r.data.rows;
            this.search();
          })
        }
      },

      handleCardBlackListAddClose() {
        this.cardBlackListAdd.visiable = false
      },
      handleCardBlackListAddSuccess() {
        this.cardBlackListAdd.visiable = false
        this.$message.success('新增卡号黑名单成功')
        this.search()
      },

      handleCardBlackListEditClose() {
        this.cardBlackListEdit.visiable = false
      },
      handleCardBlackListEditSuccess() {
        this.cardBlackListEdit.visiable = false
        this.$message.success('修改卡号黑名单成功')
        this.search()
      },


      viewCardBlackList(record) {
        let riskDate = []
        riskDate[0]=record.riskOccurTimeBegin
        riskDate[1]=record.riskOccurTimeEnd
        record.riskDate = riskDate
        var termAddrPrvnc = record.riskOccurArea.split('/');
        record.termAddrPrvnc = termAddrPrvnc[0]
        record.termAddrCity = termAddrPrvnc[1]
        this.$refs.cardBlackListInfo.setCardBlackListFormValues(record)
        this.cardBlackListInfo.visiable = true
      },
      handleCardBlackListInfoClose() {
        this.cardBlackListInfo.visiable = false
      },
      editCardBlackList(record) {
        if (record.auditStatus === '01' || record.auditStatus === '11' || record.auditStatus === '21'
          || record.auditStatus === '31' || record.auditStatus === '41') {
          this.$message.warning('申请待审批的数据不允许修改')
        } else if (record.cardBlacklistStatus === '03' ) {
          this.$message.warning('已注销数据不允许修改')
        } else {
            let riskDate = []
            riskDate[0]=record.riskOccurTimeBegin
            riskDate[1]=record.riskOccurTimeEnd
            record.riskDate = riskDate
            var termAddrPrvnc = record.riskOccurArea.split('/');
            record.termAddrPrvnc = termAddrPrvnc[0]
            record.termAddrCity = termAddrPrvnc[1]
            this.$refs.cardBlackListEdit.setCardBlackListFormValues(record)
            this.cardBlackListEdit.visiable = true
        }
      },

      search() {
        this.$refs.TableInfo.pagination.current = this.pagination.defaultCurrent
        if (this.paginationInfo) {
          this.paginationInfo.current = this.pagination.defaultCurrent
          this.paginationInfo.pageSize = this.pagination.defaultPageSize
        }

        let {sortedInfo, filteredInfo} = this
        let sortField, sortOrder
        // 获取当前列的排序和列的过滤规则
        if (sortedInfo) {
          sortField = sortedInfo.field
          sortOrder = sortedInfo.order
        }
        let params = {}
        params.instId = this.queryParams.instId
        params.acctNo = this.queryParams.acctNo

        this.fetch({
          sortField: sortField,
          sortOrder: sortOrder,
          ...params,
          ...filteredInfo
        })
      },
      reset() {
        // 取消选中
        this.selectedRowKeys = []
        // 重置分页
        this.$refs.TableInfo.pagination.current = this.pagination.defaultCurrent
        if (this.paginationInfo) {
          this.paginationInfo.current = this.pagination.defaultCurrent
          this.paginationInfo.pageSize = this.pagination.defaultPageSize
        }
        // 重置列排序规则
        this.sortedInfo = null
        // 重置查询参数
        this.queryParams = {}
        // // 清空时间选择
        // this.$refs.createTime.reset()
        this.fetch()
      },
      handleTableChange(pagination, filters, sorter) {
        this.$refs.TableInfo.pagination.current = this.pagination.defaultCurrent
        if (this.paginationInfo) {
          this.paginationInfo.current = this.pagination.defaultCurrent
          this.paginationInfo.pageSize = this.pagination.defaultPageSize
        }

        // 将这三个参数赋值给Vue data，用于后续使用
        this.paginationInfo = pagination
        this.filteredInfo = filters
        this.sortedInfo = sorter
        // this.userInfo.visiable = false

        this.fetch({
          sortField: sorter.field,
          sortOrder: sorter.order,
          ...this.queryParams,
          ...filters
        })
      },
      fetch(params = {}) {
        this.loading = true
        if (this.paginationInfo) {
          // 如果分页信息不为空，则设置表格当前第几页，每页条数，并设置查询分页参数
          this.$refs.TableInfo.pagination.current = this.paginationInfo.current
          this.$refs.TableInfo.pagination.pageSize = this.paginationInfo.pageSize
          params.pageSize = this.paginationInfo.pageSize
          params.pageNum = this.paginationInfo.current
        } else {
          // 如果分页信息为空，则设置为默认值
          params.pageSize = this.pagination.defaultPageSize
          params.pageNum = this.pagination.defaultCurrent
        }
        this.$get('/admin/merParam/cardBlackListInfo', {
          ...params
        }).then((r) => {
          let data = r.data
          const pagination = {...this.pagination}
          pagination.total = data.total
          this.dataSource = data.rows
          this.pagination = pagination
          this.loading = false
        })
      },
    }
  }
</script>

<style lang="less" scoped>
  @import "../../../../../../static/less/Common";
</style>

